import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import DevOpsLayout from '@/layout/devops-layout.vue';

export const APPLICATION_DETAIL_ROUTE: RouteRecordRaw = {
  path: ':applicationId',
  name: 'ApplicationDetail',
  meta: { title: '应用详情' },
  component: () =>
    import(
      '@/views/project/project-detail/system/system-detail/application/application-detail/application-detail-page.vue'
    ),
};

export const SYSTEM_DETAIL_ROUTE: RouteRecordRaw = {
  path: ':systemId',
  name: 'SystemDetail',
  meta: { title: '系统详情' },
  redirect: '/devops/projects/:projectId/systems/:systemId/architecture',
  component: () => import('@/views/project/project-detail/system/system-detail/system-detail-page.vue'),
  children: [
    {
      path: 'metrics',
      name: 'SystemMetrics',
      meta: { title: '系统指标' },
      component: () => import('@/views/project/project-detail/system/system-detail/system-metrics-page.vue'),
    },
    {
      path: 'architecture',
      name: 'SystemArchitecture',
      meta: { title: '当前架构' },
      component: () => import('@/views/project/project-detail/system/system-detail/system-architecture-page.vue'),
    },
    {
      path: 'target-architecture',
      name: 'TargetArchitecture',
      meta: { title: '目标架构' },
      component: () => import('@/views/project/project-detail/system/system-detail/target-architecture-page.vue'),
    },
    {
      path: 'applications',
      name: 'Applications',
      meta: { title: '应用管理' },
      component: () => import('@/views/project/project-detail/system/system-detail/application/applications-page.vue'),
      children: [APPLICATION_DETAIL_ROUTE],
    },
    {
      path: 'api-publish',
      name: 'ApiPublish',
      meta: { title: 'API 发布' },
      component: () =>
        import('@/views/project/project-detail/system/system-detail/access-control/api-publish-page.vue'),
    },
    {
      path: 'api-subscribe',
      name: 'ApiSubscribe',
      meta: { title: 'API 订阅' },
      component: () =>
        import('@/views/project/project-detail/system/system-detail/access-control/api-subscribe-page.vue'),
    },
  ],
};

export const PROJECT_DETAIL_ROUTE: RouteRecordRaw = {
  path: ':projectId',
  name: 'ProjectDetail',
  meta: { title: '项目详情' },
  component: () => import('@/views/project/project-detail/project-detail-page.vue'),
  children: [
    {
      path: 'systems',
      name: 'Systems',
      meta: { title: '系统管理' },
      component: () => import('@/views/project/project-detail/system/systems-page.vue'),
      children: [SYSTEM_DETAIL_ROUTE],
    },
  ],
};

export const DEV_OPS_TOP_ROUTES = [
  {
    path: 'projects',
    name: 'Projects',
    meta: { title: '项目' },
    component: () => import('@/views/project/projects-page.vue'),
    children: [PROJECT_DETAIL_ROUTE],
  },
  {
    path: 'global-systems',
    name: 'GlobalSystems',
    meta: { title: '系统' },
    component: () => import('@/views/workbench-page.vue'),
  },
];

export default createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      name: 'Home',
      redirect: '/devops/projects',
      meta: { title: '首页' },
    },
    {
      path: '/devops',
      name: 'DevOps',
      redirect: '/devops/projects',
      component: DevOpsLayout,
      children: DEV_OPS_TOP_ROUTES,
    },
  ],
});
